//
//  TeamHeroViewController.m
//  LOL_JewelBox
//
//  Created by dllo on 15/4/29.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "TeamHeroViewController.h"
#import "UIImageView+WebCache.h"
#import "TeamModel.h"
#import "TeamHeroCell.h"
#import "ToolsView.h"
@interface TeamHeroViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)ToolsView *toolsView;
@property(nonatomic, retain)UITableView *tableView;

@property(nonatomic, retain)NSMutableArray *desArr;  // 简介数组
@property(nonatomic, retain)NSMutableArray *heroArr; // 英雄头像数组

@end

@implementation TeamHeroViewController

- (void)dealloc
{
    
    [_desArr release];
    [_heroArr release];
    [_toolsView release];
    [_tableView release];
    [super dealloc];
    
}


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"阵容英雄详情";
        self.desArr = [NSMutableArray array];
        self.heroArr = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.toolsView = [[ToolsView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
    [self.view addSubview:self.toolsView];
    [_toolsView release];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT - 64 - 49) style:UITableViewStylePlain];
    [self.toolsView addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView release];
    
    // 详情的数组
    self.desArr = [NSMutableArray arrayWithObjects:self.teamsDes1, self.teamsDes2, self.teamsDes3, self.teamsDes4, self.teamsDes5, nil];
    // 头像的数组
    self.heroArr = [NSMutableArray arrayWithObjects:self.teamsHero1, self.teamsHero2, self.teamsHero3, self.teamsHero4, self.teamsHero5, nil];
    
}

// tableview两个必须实现的协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    TeamHeroCell *teamHeroCell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!teamHeroCell) {
        teamHeroCell = [[[TeamHeroCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
    }
    
    // 各英雄简介
    teamHeroCell.desHero.text = self.desArr[indexPath.row];
    teamHeroCell.desHero.numberOfLines = 0;
    teamHeroCell.desHero.lineBreakMode = NSLineBreakByWordWrapping;
    teamHeroCell.desHero.font = [UIFont systemFontOfSize:16];
    // 各英雄头像
    NSString *png = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/champions/%@_120x120.jpg", self.heroArr[indexPath.row]];
    NSURL *url = [NSURL URLWithString:png];
    [teamHeroCell.imageHero sd_setImageWithURL:url];
    teamHeroCell.backgroundColor = [UIColor colorWithRed:218 / 255.0 green:218 / 255.0 blue:218 / 255.0 alpha:1];
    
    // cell点击后不变色
    teamHeroCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return teamHeroCell;
}

// cell自适应高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16],NSFontAttributeName, nil];
    // 根据文本大小(font)计算出文本的rect值,最大范围不超过(375,400);
    // 第三个属性是根据什么属性来定义高度
    CGRect rect = [self.desArr[indexPath.row] boundingRectWithSize:CGSizeMake(345, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height + 90;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
